#ifndef __VFONT_H__
#define __VFONT_H__
#include "VFTFormat.h"
#define VFONT_CHARGLYPH_SIZE_MAX 64		//

#pragma pack(push)
#pragma pack(1)
struct VFontCharInfo : public VFT_CHARINFO
{
	BYTE	bitmapIndex;     ///< @note -1 indicates character is NOT to be
	BYTE	Width;
	BYTE	Height;
	BYTE	XIncrement;
	char	XOrigin;
	char	YOrigin;
	WORD	TexOfsX;
	WORD	TexOfsY;
};
#pragma pack(pop)

class VRTexture;
class VFontTexture;
class VFontGlyphInterface;

class VApi VFont : public VRefTarget
{
public:
	VFont(const VName& FaceName, int PageSize);
	virtual ~VFont(void);
	void SetCache(const char* CacheFile);
	const VFontCharInfo* GetCharInfo(wchar_t Char);
	inline const VName& GetFaceName() const { return m_FaceName;}
	inline int GetHeight() const { return m_Height;}
	inline int GetBaseLine() const { return m_BaseLine; }
	int GetStrWidth(const wchar_t* str, int len = -1);
protected:
	virtual BOOL LoadFont(const char* FontFile);
	BOOL LayoutCharGlyph(VFontCharInfo& CharInfo, const void* Glyph);
	virtual int CreateNewPage() = 0;
	virtual void FillCharGlyph(const VFontCharInfo& CharInfo, const void* Glyph) = 0;
	virtual void DeleteThis() = 0;
	VFontGlyphInterface* m_GlyphInterface;
	VName m_FaceName;
	int m_Height;
	int m_BaseLine;
	int m_SpaceXIncrement;
	struct CharLayout
	{
		inline CharLayout():CurX(0),CurY(0),CurPage(-1),PageSize(0)
		{
		}
		int CurX;
		int CurY;
		int CurPage;
		int PageSize;
	};
	CharLayout m_Layout;
};

typedef VSmartPtr<VFont> VFontPtr;

#endif
